<template>
    <div>
        <ul class="clearfix">
            <li class="white-block" v-for="item in list" :key="item.id">
                <div class="title">
                    <p class="ellipsis">{{item.name}}</p>
                    <div class="icon" @click="$router.push($route.path+'/detail/' +item.id)">
                        <i class="iconfont icon-ip-edit"></i>
                        <span>修改</span>
                    </div>

                </div>

                <div>
                    <p class="choice">已选{{item.appIpList.length}}个IP地址</p>
                    <div class="ip-a">
                        <p v-for="(items,index) in item.appIpList" :key="index"
                           v-if="(item.appIpList.length > 3 && index < 2) || item.appIpList.length < 4">
                            IP地址：{{items.ip}}</p>
                        <p v-if="item.appIpList.length > 3">...</p>
                    </div>

                </div>
                <el-link type="primary" :underline="false" class="btn" @click="openIp(item)">查看全部IP</el-link>
            </li>
            <li class="add" @click="$router.push({path: $route.path + '/add'})">
                <div>
                    <i class="iconfont icon-plus"></i>
                    <p>新增一个自建系统</p>
                </div>
            </li>
        </ul>
        <look :show.sync="visible" @save="visible=false" :ipLists.sync="appIpList"
              :currentIp="currentIp" :noCheck="true"></look>
        <transition name="slide">
            <router-view @upload="getData"></router-view>
        </transition>
    </div>
</template>

<script>
    import look from '../../components/look'

    export default {
        data() {
            return {
                list: [],
                ipList: [],
                ipList1: [],
                loading: false,
                visible: false,
                appIpList: [],
                currentIp: null
            }
        },
        mounted() {
            this.getData()
        },
        methods: {
            getData() {
                this.$http.get('/dept/workbench/listApp').then(result => {
                    if (result.success) {
                        this.list = result.data
                        this.$method.updateView()
                    }
                })
            },
            openIp(item) {
                this.visible = true
                this.currentIp = item
                this.appIpList = item.appIpList
            }
        },
        components: {
            look
        }
    }
</script>

<style scoped lang="less">
    ul {
        width: 100%;
        li {
            float: left;
            margin-right: 2%;
            margin-bottom: .3rem;
            width: 32%;
            height: 3rem;
            background-color: #fff;
            padding-left: .6rem;
            padding-right: .6rem;

            .title {
                overflow: hidden;
                margin-bottom: .1rem;
                line-height: .3rem;

                p {
                    float: left;
                    font-size: 0.2rem;
                    max-width: 80%;
                    /*padding-bottom: 0.1rem;*/
                }

                .icon {
                    float: right;
                    cursor: pointer;

                    i {
                        font-size: 0.2rem;
                        color: #4995F4;
                    }

                    span {
                        font-size: 0.16rem;
                        color: #4995F4;
                    }
                }
            }

            p {
                font-size: 0.16rem;
            }

            .choice {
                padding-bottom: .2rem;
            }

            .ip-a {
                border-top: 0.01rem solid #efefef;
                padding-top: 0.2rem;
                min-height: 1.23rem;

                p {
                    font-size: 0.16rem;
                    color: #999;
                    padding-bottom: 0.1rem;
                }
            }

            .btn {
                font-size: 0.16rem;
            }

            &:nth-child(3n) {
                margin-right: 0;
            }
        }
        .add {
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;

            i {
                font-size: 0.64rem;
                color: #DCDCDC;
            }

            p {
                color: #999;
            }
        }
    }
</style>
